#include<bits/stdc++.h>

using namespace std;

int judge(int num,int k){
	if(num%k == 0)return -1;
	if(num%10 == k)return -1;
	return 0;
}

int main(){
	int n,k;scanf("%d%d", &n,&k);
	int children[n],notalive[n];
	memset(notalive,0,sizeof(notalive));
	int index=0,num=1,pre = -1;
	while(1){
		int begin = index;
		while(notalive[index] == 1){
			index = (index+1)%n;
			if(index == pre){
				printf("%d\n", index+1);
				return 0;
			}
		}
		if(judge(num,k)){
			notalive[index] = 1;
		}
		// printf("index = %d num = %d\n", index+1,num);
		++num;
		pre = index;
		index = (index+1)%n;
	}
	
	return 0;
}